package cn.cloud.butler.webapi.repository;


import cn.cloud.butler.webapi.domain.MacGroupEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MacGroupRespository extends JpaRepository<MacGroupEntity,Long> {
    @Query(value="select Name from MacGroup where ID = (select GID from GroupMacSN where MacSN= ?1)",
            nativeQuery = true)
    String findGroupNameByMacsn(String macsn);



    @Modifying
    @Query(value = "DELETE FROM MacGroup WHERE CompID = ?1 AND NAME = ?2" ,nativeQuery = true)
    int deleteByComidAndName(Long compID, String name);


    @Query(value = "SELECT  * FROM MacGroup WHERE CompID = ?1 AND NAME = ?2  ",nativeQuery = true)
    MacGroupEntity findByCompidAndName(Long  compID,String   Name);

    List<MacGroupEntity> findByCompId(Long compId);


    MacGroupEntity findByID(Long groupId);

    @Query(value = "SELECT * from MacGroup WHERE CompID = ?1 and ID not in (SELECT GID FROM GroupMacSN )",nativeQuery = true)
    List<MacGroupEntity> selNoMacGroup(Long  compID);

}
